package com.lanchewuyou.user.driver.ui;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lanchewuyou.user.driver.R;
import com.lanchewuyou.user.driver.modul.Config;

/**
 * 司机详情页,展示司机的头像,电话
 */
public class DriverInfoActivity extends AppCompatActivity {

    private Toolbar mToolbar;
    private ImageView driverPhoto;
    private TextView driverName, driverId, driverPhone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_driver_info);
        initViews();
        SharedPreferences sharedPreferences = getSharedPreferences(Config.PASSWORD_PATH, Activity.MODE_PRIVATE);
        driverId.setText(sharedPreferences.getString("driverid", ""));
        driverName.setText(sharedPreferences.getString("drivername", ""));
        driverPhone.setText(sharedPreferences.getString("mobile", ""));
        String url = sharedPreferences.getString("driverpic", "");
        Glide.with(DriverInfoActivity.this)
                .load(url)
                .fitCenter()
                .thumbnail(0.1f)
                .placeholder(R.mipmap.touxiang)
                .error(R.mipmap.touxiang)
                .into(driverPhoto);
    }

    private void initViews() {
        mToolbar = (Toolbar) findViewById(R.id.driver_info_toolbar);
        mToolbar.setTitle("司机信息");
        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        driverId = (TextView) findViewById(R.id.driver_info_id);
        driverName = (TextView) findViewById(R.id.driver_info_name);
        driverPhone = (TextView) findViewById(R.id.driver_info_phone);
        driverPhoto = (ImageView) findViewById(R.id.driver_info_photo);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_driver_info, menu);
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }


}
